#include "stdio.h"

int maxDistToClosest(int *seats, int seatsSize) {
    int l, r, res = 0;
    while (l < seatsSize && seats[l] == 0) {
        l++;
    }
    if (l > res) {
        res = l;
    }
    while (l < seatsSize) {
        r = l + 1;
        while (r < seatsSize && seats[r] == 0) {
            r++;
        }
        if (r == seatsSize) {
            int t = r - l - 1;
            if (t > res) {
                res = t;
            }
        } else {
            int t = (r - l) / 2;
            if (t > res) {
                res = t;
            }
        }
        l = r;
    }
    return res;
}

int main() {
    int a[] = {1, 0, 0, 0, 1, 0, 1};
    printf("%d", maxDistToClosest(a, 7));
}